/**
 * @class refrigeratory.pn_north
 * @extends Ext.Panel
 *
 * 主界面上侧信息显示面板
 *
 * @author    Maple
 * @copyright (c) 2009, refrigeratory
 * @date      28. February 2011
 * @version   0.1
 * @revision  0.1
 *
 */

// create namespace
Ext.ns('refrigeratory');
refrigeratory.SITE_URL = '';

/**
 * Creates new refrigeratory.pn_north
 * @constructor
 * @param {Object} config A config object
 */
refrigeratory.pn_north = Ext.extend(Ext.Panel, {
    url: refrigeratory.REQUEST_URL,
    region:'north',
    height:54
    
    // {{{
    ,
    initComponent: function() {
        // hard coded config (it cannot be changed while instantiating)
        // {{{			
        var config = {
            items : [{
		        xtype:"box",
		        border : false,
		        el:"header"
		    },new Ext.Toolbar({items:["->", String.format("您好, {0}", refrigeratory.NAME),
		    		"-", 
		    	{xtype:'tbtext', text:new Date().format("Y年m月d日")},
		        {xtype: 'tbspacer'},
		        new Ext.form.Label({id:'lbl_rencenttime', value:''}),"-",
		        {text: '注销', handler: this.func_logout}
		]})]
        }; // eo config object

        // apply config
        Ext.apply(this, Ext.apply(this.initialConfig, config));
        // }}}

        // call parent
        refrigeratory.pn_north.superclass.initComponent.apply(this, arguments);

        // parent call post-processing, e.g. install event handlers

    } // eo function initComponent
    // }}}
    // {{{
    ,
    onRender: function() {

        // parent call pre-processing

        // call parent
        refrigeratory.pn_north.superclass.onRender.apply(this, arguments);

        // parent call post-processing, e.g. install event handlers on rendered components
        this.showTime();
		this.getIdentify();
		
		//this.setSession();
		
		

    } // eo function onRender
    // }}}
	
	,func_logout :function(){
        	Ext.Ajax.request({
        		url: refrigeratory.REQUEST_URL,
        		params:{
        			action:"user",
        			operation:"logout"
        		},
        		success:function(response){ 
        			var res = Ext.decode(response.responseText);
        			if (res.success == true)
     					setTimeout("window.location.href='"+refrigeratory.LOGIN_PAGE+"';",0);
        		 }
        	});
       }
    
    // private 显示当前时间
    ,showTime : function(){
        var time = new Date().format('h:i:s A');
        Ext.getCmp('lbl_rencenttime').setText(time);
        setTimeout(function(me){
            return function(){
                me.showTime();
            }
        }(this), '1000');
    }
	
	,getIdentify : function(time){		
		Ext.Ajax.request({
			url: "get.php",
			params: {
					action:'reFresh'
			},
			scope:this,
			success:function(response){
				var r = Ext.decode(response.responseText);
				var session = r.info;
				var nowSession = Cookies.get("session"); 
				if (r.success == true){
					if(session != nowSession){
						Ext.MessageBox.alert('提示', 
							'您已经被强制下线', this.func_logout);
					}
				}		
			}
			
		});			
		setTimeout(function(me){
			return function(){
				//me.getIdentify();
			}
        }(this), '5000');
				
	}
	
	//定时重新写session 
	/* 
	,setSession : function(){		
		Ext.Ajax.request({
			url: "get.php",
			params: {
					action:'reFresh'
			}
		});			
		setTimeout(function(me){
			return function(){
				me.setSession();
			}
        }(this), '120000');
				
	}
	*/
	
}); // eo extend

// register xtype
Ext.reg('pn_north', refrigeratory.pn_north);
// eof
